/**
 * 
 */
package io.dora.conf.spring;

import io.dora.conf.ConsumerConfig;
import io.dora.conf.ProtocolConfig;
import io.dora.conf.RegistryConfig;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;

/**
 * Consumer spring 配置Bean
 * 
 * @author zhaohongbo
 *
 */
public class ConsumerBean<T> extends ConsumerConfig<T> implements FactoryBean, ApplicationContextAware, InitializingBean, DisposableBean, ConfigInitializingBean {
	
	private ApplicationContext applicationContext;
	
	public void setBeanName(String name) {
		
	}

	public void onApplicationEvent(ApplicationEvent event) {
		
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
	}

	@Override
	public void destroy() throws Exception {
		
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		initial();
	}

	@Override
	public Object getObject() throws Exception {
		return refer();
	}

	@Override
	public Class<?> getObjectType() {
		return interfaceClass;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	@Override
	public void initial() {
		this.setRegistry(this.getBeanInstance(applicationContext, RegistryConfig.class).getRegistry());
		this.setProtocol(this.getBeanInstance(applicationContext, ProtocolConfig.class).getProtocol());
		super.initial();
	}

}
